home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / ExampleB / exampleB.cpp next >
C/C++ Source or Header  |  2001-10-08  |  9KB  |  255 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. // ===========================================================================
  30. //
  31. //    NULLSOFT WASABI SDK EXAMPLE PROJECT
  32. //
  33. //      File:     ExampleB.cpp
  34. //
  35. //!##   Purpose:  This source module that contains the functions for the 
  36. //!##             construction and utilization of the XML Document Display
  37. //!##             sheet of the ExampleB project.
  38. //
  39. //      Requires: Please read Example1.cpp first.
  40. //
  41. //      Notes:    A note on the comments in this document:
  42. //
  43. //                Notes that begin with *** are important notes that everyone
  44. //                needs to read.  The other comments assist readability or
  45. //                explain the thinking behind sections of code which may not
  46. //                be immediately obvious to the novice programmer.
  47. //
  48.  
  49.  
  50.  
  51. //
  52. //  GOOD MORNING, CAMPERS!
  53. //
  54.  
  55. //
  56. //  For exampleB, we're still gonna just ignore most of this file 
  57. //  and play with the ExampleBWnd.cpp file (for the most part).
  58. //
  59. //  As before, there are a handful of things you should know about
  60. //  this file first.  Most specifically, you gotta edit all the
  61. //  "//EDITME" lines.  I'll tag out the info as to what all this
  62. //  stuff does inline with the code there.
  63. //
  64.  
  65. //
  66. //  Headers, Headers, Headers, Headers.
  67. #include "../common/std.h"  // Always start with std.h
  68. #include "../common/xlatstr.h"
  69.  
  70. #include "ExampleB.h"     //EDITME
  71. #include "ExampleBWnd.h"  //EDITME
  72.  
  73. #include "resource.h"
  74.  
  75. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  76. #include "../studio/services/servicei.h"     // For the service template.
  77. #include "../studio/services/svc_wndcreate.h"
  78. #include "../common/SimpleWndCreate.h"
  79. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  80.  
  81.  
  82. // ===========================================================================
  83. //
  84. //  Amusing static instantiations.  Your component should live as a static
  85. // data object in your primary module (well, phooey, you can put the damn
  86. // thing anywhere -- just make sure you make one)
  87. static WACNAME wac;
  88. WACPARENT *the = &wac;                     
  89. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  90. WACNAME * WACNAME::myInstance = NULL;
  91. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  92.  
  93.  
  94. // ===========================================================================
  95. //
  96. //  *** You MUST use a unique GUID for your WAC files.
  97. //
  98. //  Making it be a local data item makes it easy to centralize.
  99. //  You have to return this value from the Component's getGuid() method.
  100. //
  101. //  Trust me.  This one isn't optional.  Do it, and do it NOW.
  102. // {84E9B291-1701-449c-9E7E-AB96D65BC878}
  103. GUID exb_guid = { 0x84e9b291, 0x1701, 0x449c, { 0x9e, 0x7e, 0xab, 0x96, 0xd6, 0x5b, 0xc8, 0x78 } }; 
  104. //EDITME (hint: use guidgen.exe)
  105.  
  106.  
  107. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  108. // ===========================================================================
  109. //
  110. // *** WindowCreationServiceObject for this example.
  111. static waServiceT<svc_windowCreate, ThingerWndCreateSvc< WACNAME > >  ExampleB_WndCreateSvc;
  112. //
  113. //  For now, in order to allow your component to create a window in the GUI
  114. //  into which it may place its functionality, you need to create the above
  115. //  template instantiation and then use it in your onRegisterServices() and
  116. //  onDestroy() calls.
  117. //
  118. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  119.  
  120. // ===========================================================================
  121. //
  122. //  This "Fortify" stuff is nice happy memory handling and leak detection.
  123. //  You might learn about the specifics of it sometime in the future but,
  124. //  for now, change the output .WAC filenames for your debug and release
  125. //  files here.
  126. WACNAME::WACNAME() {
  127. #ifdef    FORTIFY
  128.   FortifySetName("ExampleB.wac");   // EDITME
  129.   FortifyEnterScope();
  130. #endif  //FORTIFY
  131.   wnd = NULL;
  132.  
  133. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  134.   // Helper data for the window creation service
  135.   ASSERT( myInstance == NULL );
  136.   myInstance = this;
  137. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  138. }
  139.  
  140. WACNAME::~WACNAME() {
  141. #ifdef FORTIFY
  142.   FortifyLeaveScope();
  143. #endif
  144. }
  145.  
  146. // ===========================================================================
  147. //
  148. // Ah, well, yes.  There's one problem with GUIDs.  Nobody will be
  149. // able to tell that component {6DC73FE8-6D34-4942-950A-FF2370329BB0}
  150. // is the really kickass breadslicing component you've written for
  151. // Winamp3.0 -- so you gotta actually give it at least a SEMI unique
  152. // name in english, too.
  153. const char *WACNAME::getName() {
  154.   return "ExampleB Component"; //EDITME
  155. }
  156.  
  157. GUID WACNAME::getGUID() {
  158.   return exb_guid;
  159. }
  160.  
  161. void WACNAME::onCreate() {
  162.   // *** Do startup stuff here that doesn't require you to have a window yet
  163. }
  164.  
  165. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  166. int WACNAME::destroyWindow(RootWnd * deadWnd) {
  167.   if ((deadWnd != NULL)&&(deadWnd == wnd)) {
  168.     delete deadWnd;
  169.     wnd = NULL;
  170.     return 1;
  171.   }
  172.   return 0;
  173. }
  174.  
  175. ThingerBitmapInfo WACNAME::getThingerBitmapInfo() {
  176.   return ThingerBitmapInfo(gethInstance(), IDB_TAB_NORMAL, NULL, IDB_TAB_HILITED, IDB_TAB_SELECTED);
  177. }
  178.  
  179. void WACNAME::onRegisterServices() {
  180.   // ***  Register our window creation service here.
  181.   //      If we don't do this, we don't get a window.
  182.   api->service_register(&ExampleB_WndCreateSvc); 
  183.   api->register_autoPopupGUID(getGUID(), getName());
  184. }
  185. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  186.  
  187. void WACNAME::onDestroy() {
  188. // WCS: START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  189.   // ***  Deregister our window creation service here.
  190.   //      If we don't do this, we get a memory leak.
  191.   api->service_deregister(&ExampleB_WndCreateSvc);
  192. // WCS: END   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  193.   // *** Be sure to delete all your windows etc HERE, not in the destructor,
  194.   //     because the API pointer might be invalid in the destructor
  195.   delete wnd; wnd = NULL;
  196.   WACPARENT::onDestroy();
  197. }
  198.  
  199.  
  200.  
  201.  
  202. //
  203. //  When the API asks you to make your window, you make your window.
  204. //  NO.
  205. //     QUESTIONS.
  206. //               ASKED.
  207. //
  208. RootWnd *WACNAME::createWindow(int n, RootWnd *parentWnd) {
  209.   if (n == 0) {
  210.     //
  211.     //  You've seen this before.  There's nothing new here.
  212.     //  We make our window, and then we grooove with it.
  213.     if (wnd != NULL) 
  214.       return NULL;
  215.  
  216.     wnd = new ExampleBWnd;
  217.  
  218.     //
  219.     //  But we're not just making a blankeyblank window for painting.
  220.     //
  221.     //  Oh, no SIR!
  222.     //
  223.     //  We're gonna make all KINDS of nasty windowlets in this
  224.     //  mild exercise in constrained psychosis.  It'll be fun.
  225.     //
  226.     //  Trust me.
  227.     //
  228.  
  229.     //
  230.     //  So, here's the plan: we get a bunch of sea monkeys, and train them
  231.     //  to use automatic weapons.  Then...
  232.     //
  233.     //  Errr, wait... that's this weekend's plans.  Sorry.
  234.     //
  235.     //  RIGHT.  Found it.  HERE'S the real plan:
  236.     //
  237.     //      1) Figure out how to use the Tabsheet UIO
  238.     //      2) Implement a Tabsheet UIO with LOTS of (lots of) Tabs.
  239.     //      3) Implement some examples of SDK functionality into each tabsheet.
  240.     //      4) FEEL the LOVE.
  241.     //
  242.  
  243.     //
  244.     //  Ready to dive in, face first?
  245.     //
  246.     //  Let's go!
  247.     //            ON to ExampleBWnd.cpp, my good man!  MUSH!
  248.     //
  249.     wnd->init(parentWnd);
  250.     return wnd;
  251.   }
  252.   return 0;
  253. }
  254.  
  255.